package com.system.log.web;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.system.common.util.ExtAjaxResponse;
import com.system.common.util.ExtPageable;
import com.system.log.entity.Log;
import com.system.log.entity.DTO.LogDTO;
import com.system.log.service.ILogService;
@Controller
@RequestMapping("/log")
public class LogController 
{
	@Autowired
	private ILogService logService;
	@RequestMapping("/saveOrUpdate")
	public @ResponseBody ExtAjaxResponse saveOrUpdate(Log log) 
	{
		try {
			if(log.getLogId()==null) {
			logService.saveOrUpdate(log);
			return new ExtAjaxResponse(true,"部门增加成功");
			}else {			
				logService.saveOrUpdate(log);
			return new ExtAjaxResponse(true,"部门信息更新成功");
			}
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"部门信息更新失败");
		}
	}
	@RequestMapping("/delete")
	public @ResponseBody ExtAjaxResponse Delete(@RequestParam Long logId) {
		try {
			Log log = logService.findOne(logId);
			logService.delete(log);
			return new ExtAjaxResponse(true,"删除成功");
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"删除失败");
		}
	}
	@RequestMapping("/deleteLogs")
	public @ResponseBody ExtAjaxResponse Deletes(@RequestParam Long[] ids) {
		try {
			List<Long> lists = Arrays.asList(ids);
			if (null!=lists) {
				logService.delete(lists);
			}
			return new ExtAjaxResponse(true,"删除成功");
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"删除失败");
		}	
	}
	@RequestMapping("/findOne")
	public @ResponseBody Log findOne(@RequestParam Long logId) 
	{
		Log log =  logService.findOne(logId);
		
		return log;
	}

	@RequestMapping("/findAll")
	public @ResponseBody List<Log> findAll() 
	{
		 List<Log> lists =  logService.findAll();
		
		return lists;
	}
	@RequestMapping("/findPage")
	public @ResponseBody Page<Log> findPage(LogDTO logDTO,ExtPageable pageable) 
	{
		Page<Log> page =  logService.findAll(LogDTO.getSpecification(logDTO), pageable.getPageable());
		
		return page;
	}
}
